package cn.yangliu.nacos.comm.oauth;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import cn.yangliu.nacos.comm.model.Oauth2Token;
import org.springframework.stereotype.Component;

/**
 * The type of nacos.
 *
 * @author 问道于盲
 * @date 2020 -01-01
 */
@Component
public class DefaultTokenHandler implements TokenHandler {

    /**
     * current class's static member
     * The constant OAUTH_2_TOKEN_MAP.
     */
    private static final Map<String, Oauth2Token> OAUTH_2_TOKEN_MAP = new ConcurrentHashMap<>();

    /**
     * Load oauth 2 token.
     *
     * @param username the username
     * @return the oauth 2 token
     */
    @Override
    public Oauth2Token load(String username) {
        return OAUTH_2_TOKEN_MAP.get(username);
    }

    /**
     * Store.
     *
     * @param username the username
     * @param token    the token
     */
    @Override
    public void store(String username, Oauth2Token token) {
         OAUTH_2_TOKEN_MAP.put(username, token);
    }
}
